Skip to content

Conversation

Tapeline
Copy link
Contributor

@Tapeline Tapeline commented Sep 17, 2025

@Tapeline Tapeline marked this pull request as ready for review September 17, 2025 21:02
UNBOUNDLOCAL_ERROR_MSG,
PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, oparg)
);
name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is better no to break the declaration and the assignment?

name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames,
oparg);
const char *err_msg = PyMapping_HasKey(BUILTINS(), name)
? CANNOT_DELETE_BUILTIN_ERROR_MSG
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to proper align these two lines.

Copy link
Contributor Author

@Tapeline Tapeline Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't generated_cases.c.h be left without review?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is a generated file.

ERROR_NO_POP();
}
if (err == 0) {
const char *err_msg = PyMapping_HasKey(BUILTINS(), name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is safe to use PyDict_* here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no PyDict_* equivalent of PyMapping_HasKey, but we should be using PyMapping_HasKeyWithError here.

ERROR_NO_POP();
}
if (err == 0) {
const char *err_msg = PyMapping_HasKey(BUILTINS(), name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no PyDict_* equivalent of PyMapping_HasKey, but we should be using PyMapping_HasKeyWithError here.

PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames, oparg)
);
PyObject *name;
name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyTuple_GetItem can fail. We should be able to expect that it can't, so let's use PyTuple_GET_ITEM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we leave this as is? This seems like an unrelated change.

PyObject *name;
name = PyTuple_GetItem(_PyFrame_GetCode(frame)->co_localsplusnames,
oparg);
const char *err_msg = PyMapping_HasKey(BUILTINS(), name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto -- we should be using PyMapping_HasKeyWithError.

@@ -0,0 +1 @@
Deleting builtin names with ``del`` now gives a clearer error message.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Deleting builtin names with ``del`` now gives a clearer error message.
Deleting built-in names with :keyword:`del` now gives a clearer error message.


def test_builtin_deletion_err_message(self):
with self.assertRaisesRegex(
NameError, "cannot delete builtin 'all'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting makes this a bit difficult to read. This isn't coming near PEP 8's 79 character limit, so let's just keep all the arguments on the same line. This applies to all the assertRaisesRegex calls below.

Try to fit C code in reasonable width
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants